#include <iostream>
using namespace std;
class Complex
{
public:
    Complex(double r=0,double i=0):re(r),im(i) {}
    void print()
    {
        cout<< re <<" + " << im <<"i\n";
    }

    friend int operator>(Complex cm1,Complex cm2);

private:
    double re;//实部
    double im; //虚部
};
int operator>(Complex cm1,Complex cm2)
{
    if(cm1.re*cm1.re+cm1.im*cm1.im > cm2.re*cm2.re+cm2.im*cm2.im)
        return 1;
    else
        return 0;
}

//函数模板Max
template < typename Type>
Type Max( Type a, Type b ) 
{     
    if ( a >b )     
        return a ;
    else 
        return b;
}


int main()
{
  cout << "Max(t, v) = " <<Max('t', 'v') << endl;
  cout << "Max(10.1, 15.2) = " <<Max(10.1, 15.2) << endl;
  cout << "Max(5, 6) = "<<Max <int> (6,5) <<endl;
  cout << "Max(bag, big) = " << Max("bag","big") << endl; //bug,不能实现strcmp功能

  Complex cm1(3,2),cm2(-5,-6),cm3;
  cm3=Max(cm1, cm2);
  cm3.print();
  return 0;
}
